<!DOCTYPE html>
<html lang="en">
<head>
    <title>销售绩效考核报表</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--插件样式-->
    <link href="/dist/plugins/ztree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet"/>
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=4a6c1b54">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=16f1e6f3">
    <script src="https://file.ggxqce.com/web/vue.min.js"></script>
    <style>
        .moduleName {
            height: 28px;
            line-height: 28px;
            font-size: 22px;
            border-bottom: 1px solid #ddd;
            text-align: center;

        }

        .tryStyle {
            width: 30px;
            height: 14px;
            line-height: 14px;
            font-size: 12px;
            /* top: 0; */
            right: 0;
            position: absolute;
            border-radius: 5px;
            margin-top: 1px;
            background: red;
            color: #fff;
            margin-right: -2px;
            transform: scale(0.8);
        }

        .nav-tabs-custom {
            padding: 10px 0;
            margin-bottom: 0px;
            box-shadow: none;
            position: relative;
            overflow: hidden;

        }

        .infoReport {
            display: flex;
            justify-content: flex-start;
            text-align: left;
            margin-left: 10px;
        }

        .infoReport div {
            margin: 0 10px;
        }

        .lineOne {
            text-align: left;
        }

        .lineOne span {
            max-height: 20px;
            line-height: 20px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            text-align: left;

        }

        .lineOneNoMore {
            text-align: left;
        }

        .lineOneNoMore span {
            max-height: 20px;
            line-height: 20px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            text-align: left;
        }

        .mScrollBox {
            float: left;
            position: relative;
        }

        .imgStyle {
            width: 300px;
            height: 400px;
        }

        .div-td-content-more {
            position: absolute;
            height: auto;
            z-index: 999;
            line-height: 20px;
            background-color: #d3e8fd;
            padding: 8px 6px;
            border: 1px solid #e8e8ea;
            display: none;
        }

        .div-td-content-more i {
            width: 15px;
            height: 12px;
            background: url("/dist/img/more-icon.png");
            position: absolute;
            left: 50px;
            top: -12px;
        }

        .templateStyle {
            border: 1px solid #ddd;
            padding: 0 10px;
        }

        .table > thead > tr > th {
            padding: 0;
        }

        .table > tbody > tr > td {
            position: relative;
        }

        .selectBox {
            height: 25px;
            margin-bottom: 10px;
        }

        .lineOne {
            text-align: center;
        }

        .lineOne span {
            max-height: 20px;
            line-height: 20px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            text-align: center;
        }

        .left {
            width: 150px;
            float: left;
        }

        .right {
            margin-left: 160px;
        }
    </style>
</head>
<body>
<iframe id="ifAttach" style="display:none"></iframe>
<div class="div-td-content-more"><i></i></div>
<section class="content" id="app" v-cloak>
    <iframe id="ifExprot" style="width:0px;height:0px;display: none;" frameborder="0"></iframe>
    <div class="row">
        <div class="left" id="inboxGroup" id="divLeft">
            <div class="box-body no-padding box-border iframeH" style="overflow: auto;background: #f7f8fa;">
                <ul class="ztree" id="ztree"></ul>
            </div>
        </div>
        <div class="right" id="divMiddle">
            <div class="templateStyle iframeH" style="overflow-y: auto">
                <div class="nav-tabs-custom oaReportNav">
                    <!-- Tabs within a box -->
                    <!-- <input type="text" @focus="showDatePicker2($event)" v-model="time" style="width:124px;float: left;  height: 28px; margin-bottom: 10px;">
                     <input type="button" style="margin-left:10px;margin-top: 2px;width: 60px" class="btn oaBtn btn-sm pull-left" value="导出"
                            @click="exportExcel()" >
                     <div class="moduleName" >销售绩效考核报表({{time}})</div>
               -->
                    <div class="moduleName" style="float: left">销售绩效考核报表</div>
                    <ul class="nav nav-tabs pull-right" style="margin-bottom: 10px;" v-cloak>
                        <li class="active" @click="refreshData('selectParameter','getTableData',thisMonth)"
                            style="position: relative;left: 10px"><a href="#sales-chart"
                                                                     data-toggle="tab">本月</a>
                        </li>
                        <li v-for="(item,i) in tab" @click="refreshData('selectParameter','getTableData',item.time)"
                            style="position: relative;left: 10px"><a
                                href="#sales-chart" data-toggle="tab">{{i==0?"上月":item.str}}</a>
                        </li>
                        <li style="float: right;margin-top: -2px;"><input type="button"
                                                                          style="margin-left:10px;margin-top: 2px;width: 60px"
                                                                          class="btn oaBtn btn-sm pull-left" value="导 出"
                                                                          @click="exportExcel()"></li>
                    </ul>


                </div>
                <!--<div class="selectBox">-->
                <!--&lt;!&ndash;<input type="text" placeholder="姓名" class="form-control pull-left input-sm" v-model="selectParameter.name" style="width: 120px; ">&ndash;&gt;-->
                <!--<input type="text" v-model="selectParameter.dateTime" @focus="showDatePicker($event)" placeholder="请选择日期" class="form-control pull-left input-sm" style="width: 120px;"/>-->
                <!--<button type="button" class="btn oaBtn btn-sm" style="margin-left: 10px;" @click="getTableData">查询</button>-->
                <!--</div>-->

                <table class="table text-center table-width">
                    <thead>
                    <tr>
                        <th style="width: 100px" class="tableTitle">公司</th>
                        <th style="width: 65px" class="tableTitle">岗位</th>
                        <th style="width: 100px" class="tableTitle">区域</th>
                        <th style="width: 65px" class="tableTitle">负责人</th>
                        <th style="width: 65px" class="tableTitle">考核周期(月)</th>
                        <th style="width: 70px;" class="tableTitle">目标</th>
                        <th style="width: 65px;" class="tableTitle">完成</th>
                        <th style="width: 65px;" class="tableTitle">奖励金额</th>
                        <th style="width: 65px;" class="tableTitle">罚款金额</th>
                        <th style="width: 65px" class="tableTitle">奖惩合计</th>
                        <th style="width: 65px" class="tableTitle">目标完成情况</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr v-for="(item,i) in managerList" v-if="item.companyName!='重庆迎风'">
                        <td :rowspan="item.companyNamespan" :class="{hidden: item.companyNamedis}">
                            {{item.companyName}}
                        </td>
                        <td :rowspan="item.roleNamespan" :class="{hidden: item.roleNamedis}"
                            style="border-left: 1px solid #cbcbcd;border-right: 1px solid #cbcbcd;">{{item.roleName}}
                        </td>
                        <td v-if="item.roleName=='总经理'|| item.roleName=='销售总监'||item.roleName=='区域总监'">
                            {{item.companyName}}
                        </td>
                        <td v-else class="lineOne"><span>{{item.regionName}}</span></td>
                        <td>{{item.userName}}</td>
                        <td>{{item.cycle}} 月</td>
                        <td>{{item.targetNum?item.targetNum:"-"}}</td>
                        <td>{{item.finishNum?item.finishNum:"-"}}</td>
                        <!--<td>-</td>-->
                        <td>{{item.saleReward?item.saleReward:"-"}}</td>
                        <td>{{item.salePunishment?item.salePunishment:"-"}}</td>
                        <td>{{item.money?item.money:"-"}}</td>
                        <td :style="(Number(item.finishNum)< Number(item.targetNum))||!item.finishNum||!item.targetNum?'color:red':''">
                            {{(Number(item.finishNum)<
                            Number(item.targetNum))||!item.finishNum||!item.targetNum?"未完成":"已完成"}}
                        </td>
                        <!--<td style="color: red;">未完成</td>-->
                    </tr>
                    <tr>
                        <td colspan="11" style="background: #f8f8f8;"></td>
                    </tr>
                    <template v-for="(item,i) in tableData">

                        <tr v-if="item.roleName">
                            <td :rowspan="item.companyNamespan" :class="{hidden: item.companyNamedis}"
                                style="border-right: 1px solid #cbcbcd;">{{item.companyName}}
                            </td>
                            <td :rowspan="item.roleNamespan" :class="{hidden: item.roleNamedis}"
                                style="border-right: 1px solid #cbcbcd;">{{item.roleName}}
                            </td>
                            <td v-if="item.roleName=='总经理'|| item.roleName=='销售总监'||item.roleName=='区域总监'">
                                {{item.companyName}}
                            </td>
                            <td v-else class="lineOne"><span>{{item.regionName}}</span></td>
                            <td>{{item.userName}}</td>
                            <td>{{item.cycle}} 月</td>
                            <td>{{item.targetNum?item.targetNum:"-"}}</td>
                            <td>{{item.finishNum?item.finishNum:"-"}}</td>
                            <!--<td>-</td>-->
                            <td>{{item.saleReward?item.saleReward:"-"}}</td>
                            <td>{{item.salePunishment?item.salePunishment:"-"}}</td>
                            <td>{{item.money?item.money:"-"}}</td>
                            <td :style="(Number(item.finishNum)< Number(item.targetNum))||!item.finishNum||!item.targetNum?'color:red':''">
                                {{(Number(item.finishNum)<
                                Number(item.targetNum))||!item.finishNum||!item.targetNum?"未完成":"已完成"}}
                            </td>
                            <!--<td style="color: red;">未完成</td>-->
                        </tr>
                        <tr v-else>
                            <td :rowspan="item.companyNamespan" :class="{hidden: item.companyNamedis}">
                                {{item.companyName}}
                            </td>
                            <td colspan="10" style="background: #f8f8f8;"></td>
                        </tr>

                    </template>

                    </tbody>
                </table>
            </div>
        </div>
    </div>
</section>
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=8e743a31"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=54c6b89c"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script type="text/javascript" src="/dist/plugins/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<!--ztree组件所需js-->
<script type="text/javascript" src="/dist/plugins/ztree/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="/dist/plugins/ztree/js/jquery.ztree.exhide-3.5.js"></script>
<script>
    $(function () {
        $("body").on("click", ".lineOne", function (e) {
            if ($(".div-td-content-more").is(":hidden")) {
                var text = $(this).text();
                if (text != "") {
                    text = "<i></i>" + text;
                    $(".div-td-content-more").html(text).css({
                        "width": $(this).outerWidth() + "px",
                        "left": $(this).offset().left,
                        "top": ($(this).offset().top + $(this).outerHeight()) + "px"
                    }).show();
                    e.stopPropagation();
                }
            } else {
                $(".div-td-content-more").hide();
            }
        });
        $("body").on("click", ".div-td-content-more", function (e) {
            e.stopPropagation();
        });
        $("body").on("click", function () {
            $(".div-td-content-more").hide();
        });
    });
</script>
<script type="text/javascript">
    var zTreeCallback = {
        showIcon: function (treeeId, treeNode) {
            return treeNode.isParent;
        },
        onClick: function (event, treeId, treeNode) {
            console.log(treeNode)
            app.selectParameter.companyId = treeNode.id;
            app.selectParameter.name = '';
            app.getTableData();
        },
        beforeClick: function (treeId, treeNode, clickFlag) {
            if (treeNode.level == 0) {
                return false;
            }
        }
    };
    var zTreeSetting = {
        view: {
            showIcon: zTreeCallback.showIcon
        },
        data: {
            simpleData: {
                enable: true
            },
            keep: {
                parent: true
            }
        },
        callback: {
            onClick: zTreeCallback.onClick,
            beforeClick: zTreeCallback.beforeClick
        }
    };

</script>
<script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data: {
            tab: [],
            thisMonth: new Date().Format("yyyy-MM"),
            test: {
                companyId: getCurrentUser().companyId,
                roleName: getCurrentUser().roleName,
                dateTime: new Date().Format("yyyy-MM"),
            },
            year: 2017,
            month: 12,
            time: new Date().Format("yyyy-MM"),
            managerList: [],
            list: [],
            tableData: [],
            tableAllData: {},
            day: new Date().Format("yyyy-MM-dd"),//今天
            selectParameter: {
                companyId: "",
                name: "",
                dateTime: new Date().Format("yyyy-MM"),//今天
            },

        },
        methods: {
            //格式化日期
            insert_flg: function (str, flg, sn, type) {
                var newstr = "";
                for (var i = 0; i < str.length; i += sn) {
                    var tmp = str.substring(i, i + sn);
                    newstr += tmp + flg;
                }
                newstr = newstr.substr(0, newstr.length - 1);
                var st1 = newstr.substr(2, 2);
                var st2 = newstr.substr(5, 2);
                var newstr3 = st2 + "/" + st1;
                var obj = {str: newstr, time: newstr};
                return obj;
            },
            getLastEndMonth: function (beginYearMonth) {
                var strYear = parseInt(beginYearMonth.substr(0, 4), 10);
                var strMonth = parseInt(beginYearMonth.substr(4, 6), 10);
                if (strMonth - 1 == 0) {
                    strYear -= 1;
                    strMonth = 12;
                } else {
                    strMonth -= 1;
                }
                if (strMonth < 10) {
                    strMonth = "0" + strMonth;
                }
                var monthstr = strYear + "" + strMonth;
                return monthstr;
            },
            //获取tab
            getTab: function () {
                var that = this;
                var dateTime = new Date().Format("yyyyMM");

                for (var i = 0; i < 5; i++) {
                    dateTime = that.getLastEndMonth(dateTime);
                    that.tab.push(that.insert_flg(dateTime, "-", "4"))
                }
                console.log(that.tab)
            },
            //tab中点击日期刷新对应数据
            refreshData: function (dataType, fun, time) {
                var that = this;
                console.log(fun)
                console.log(time)
                // that[dataType].dateTime = time;
                that.selectParameter.dateTime = time;
                that.time = time;
                that.test.dateTime = time;
                that[fun]();
            },
            showDatePicker2: function (e) {
                var that = this;
                WdatePicker({
                    onpicked: function (dp) {
                        that.selectParameter.dateTime = dp.cal.getNewDateStr();
                        that.time = dp.cal.getNewDateStr();
                        that.test.dateTime = dp.cal.getNewDateStr();
                        that.getTableData();
                        return true;
                    },
                    dateFmt: 'yyyy-MM'
                });
                $(e.target).blur();
            },
            //获取合计
            getCount: function (arr, key) {
                var number = 0;
                for (var i = arr.length - 1; i >= 0; i--) {
                    number += Number(arr[i][key] && arr[i][key] != '-' ? arr[i][key] : 0)
                    if (key == "monthMoney") {
                        console.log(arr[i][key])
                    }
                }
                return number;
            },
            exportExcel: function () {
                var that = this;
                var selectCompanyId = that.selectParameter.companyId
                $('#ifExprot').attr('src', server.ip
                    + "/regionAchivementsService/getDownByCondition.json"
                    + '?companyId=' + that.test.companyId + "&&dateTime=" + that.test.dateTime + "&&roleName=" + that.test.roleName + "&&selectCompanyId=" + selectCompanyId
                );
            },
            //初始化时间控件
            showDatePicker: function (e, type) {
                var that = this;
                WdatePicker({
                    onpicked: function (dp) {
                        that.selectParameter.dateTime = dp.cal.getNewDateStr();
                        return true;
                    },
                    dateFmt: 'yyyy-MM'
                });
                $(e.target).blur();
            },
            //合并单元格
            tablesMergeCell: function (list) {
                for (field in list[0]) {
                    var k = 0;
                    while (k < list.length) {
                        list[k][field + 'span'] = 1;
                        list[k][field + 'dis'] = false;
                        for (var i = k + 1; i <= list.length - 1; i++) {
                            if (list[k][field] == list[i][field] && list[k][field] != '') {
                                list[k][field + 'span']++;
                                list[k][field + 'dis'] = false;
                                list[i][field + 'span'] = 1;
                                list[i][field + 'dis'] = true;
                            } else {
                                break;
                            }
                        }
                        k = i;
                    }
                }
                return list;
            },
            getTableData: function () {
                var that = this;
                $.wyui.postMethod(urlConfig.warNewspaper.regionAchivementsService.getManagerSale, {
                    companyId: getCurrentUser().companyId,
                    roleName: getCurrentUser().roleName,
                    dateTime: that.time
                }, function (data) {
                    var records = data.records;
                    that.managerList = that.tablesMergeCell(records);
                });
                $.wyui.postMethod(urlConfig.warNewspaper.regionAchivementsService.getSale, that.selectParameter, function (data) {
                    console.log(data);
                    var data = data.records;
                    var newdata = []
                    for (var i = 0; i < data.length; i++) {
                        newdata.push(data[i])
                        if (i != data.length - 1) {
                            if (data[i].roleName != data[i + 1].roleName) {
                                newdata.push({"companyName": data[i].companyName})
                            }
                        }

                    }
                    that.tableData = that.tablesMergeCell(newdata);
                    that.tableAllData.finishNum = that.getCount(data, "finishNum")
                    that.tableAllData.targetNum = that.getCount(data, "targetNum")
                    that.tableAllData.saleReward = that.getCount(data, "saleReward")
                    that.tableAllData.salePunishment = that.getCount(data, "salePunishment")
                    that.tableAllData.money = that.getCount(data, "money")
                })
            },
            getTreeData: function () {
                var that = this;
                $.wyui.postMethod(urlConfig.system.system.getCompanyTree, {
                    companyId: getCurrentUser().companyId,
                    userId: getCurrentUser().id
                }, function (nodes) {
                    console.log(nodes);
                    for (var i = 0; i < nodes.length; i++) {
                        if (nodes[i].name == '重庆迎风') {
                            nodes.splice(i, 1);
                        }
                    };
                    for (var b = 0;b < nodes.length; b++) {
                        if (nodes[b].name == '江苏灜沣') {
                            nodes.splice(b, 1);
                        }
                    };
                    that.treeObj = $.fn.zTree.init($("#ztree"), zTreeSetting, nodes);
                    var treeObj = $.fn.zTree.getZTreeObj("ztree");
                    var nodes = treeObj.getNodes();
                    console.log(nodes)
                    if (nodes[0].children[0]) {
                        treeObj.selectNode(nodes[0].children[0]);
                        that.selectParameter.companyId = nodes[0].children[0].id;
                        that.getTableData();
                    }
                });
            }
        },
        mounted: function () {
            var that = this;
            //1.获取前5个月的tab数据
            this.getTab();
            that.getTreeData();
        }
    });

</script>

</body>
</html>